using Microsoft.VisualStudio.Modeling.Diagrams;

namespace Microsoft.Modeling.StoryboardDesigner
{
    /// <summary>
    /// TextField subclass: automatically resizes to the 
    /// size required to display the text by changing the
    /// height of the field.
    /// </summary>
    public class AutoSizeTextField : TextField
    {
        public AutoSizeTextField(string fieldName)
            : base(fieldName)
        {
        }

        public override RectangleD GetBounds(ShapeElement parentShape)
        {
            // How big would the field normally be?
            RectangleD baseBounds = base.GetBounds(parentShape);

            //// Now work out how big this field needs to be to display
            //// all of the text.
            SizeD requiredSize = 
                MultiLineFieldHelper.GetRequiredSizeForFixedWidth(
                    parentShape, 
                    this, 
                    baseBounds.Width);

            // Ensure that the field is high enough to display
            // all of the text
            // NB comparing doubles, so might not be exact.
            if((requiredSize.Height - baseBounds.Height > 0.000001))
            {
                baseBounds.Height = requiredSize.Height;
            }

            return baseBounds;
        }
    }
}